// pages/toCity/toCity.js
const app = getApp();

Page({
  data: {
    nowCity:""
  },

  onLoad: function (options) {
    wx.getLocation({
      type: 'wgs84',
      success: (res)=>{
        var url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${res.latitude},${res.longitude}&key=MIPBZ-ZC5WR-TFVWM-WW4PX-RS3XZ-7KBG2`
        // 根据百度地图api获取城市
        wx.request({
          url,
          data: {},
          method: 'GET',
          success: (res)=>{
            console.log(res.data.result.address_component.city);
            wx.setStorageSync('position', res.data.result.address_component.city)
            var nowCity = wx.getStorageSync('position')
            this.setData({
              nowCity,
            })
          }
        })
      }
    })
  },
  onShow:function(){
    var nowCity = wx.getStorageSync('nowCity')
    this.setData({
      nowCity,
    })
  },
  onGoto(event){
    wx.navigateTo({
      url: '/pages/city/city',
    })
  }
})